package com.example.park

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.example.lib_base.entity.CarTypeEntityItem
import com.example.lib_base.net.ApiService
import java.time.LocalDate

class ParkSource(val apiService: ApiService):PagingSource<Int,CarTypeEntityItem>() {
    override fun getRefreshKey(state: PagingState<Int, CarTypeEntityItem>): Int? {
        return null
    }

    override suspend fun load(params: LoadParams<Int>): LoadResult<Int, CarTypeEntityItem> {
        try {
            //当前
            val currentPage = params.key?:0
            //网络
            val carType = apiService.getCarType("标准车位")
           val nextPage = if(carType.data.size == 10)currentPage+1 else null
            return LoadResult.Page(carType.data,null,nextPage)
        }catch (e:Exception) {
            return LoadResult.Error(e)
        }
    }
}